<?php
	
	/*
		script: smuoi-prepend.php
	
		The first include in SMUOI.  This script is as brief as possible since its purpose 
		is to determine whether the user intends to invoke SMUOI at all.	

	
		function: we_smuoi

		Determines whether SMUOI is to be invoked.

		Possible SMUOI environment variable values -
			- equate false (including strings "false" and "0") == do not invoke
			- string "run" == all files invoke, file runs (exit)
			- array of extensions == files whose extension is an array member invoke
			- equate true == all files invoke	
		Any further processing instructions are read during <Domain::run>.

		The most efficient instruction that prevents SMUOI from running in a directory 
		is to simply unset the variable. In apache, do

		>	UnSetEnv SMUOI

		or if you run PHP as an apache module even better is to do

		>	php_value auto_prepend_file ""

		Of course, be sure to remove any extra handlers (such as .html) you had set to invoke php.
	*/
	
	function we_smuoi(){
		if((!$e = getenv('SMUOI'))||(!$e = smuoi_readenv($e))) return false;
		if(!is_array($e)) return true;
		$sf = $_SERVER["SCRIPT_FILENAME"];
		return is_array($e) ? in_array(strtolower(substr($sf, strrpos($sf, '.')+1)), $e) : true;
	}

	/*
		function: smuoi_readenv
		
		Reads environment variables allowing for extra syntactical expressions.

		Special syntax:
			- Arrays may be sent using the simple syntax [member1,member2,member3]
			- The booleans may be sent as their lowercase string equivalents.

		params: 
			e - The name of the environment variable to be referenced
	*/

	function smuoi_readenv($e){
		if(is_numeric($e)) return (int)$e;
		if(!$e) return $e;
		if($e[0] == '[' && $e[strlen($e)-1] == ']') return explode(',', substr($e, 1, -1));
		return ($e == 'false') ? false : (($e == 'true') ? true : $e);
	}
	
	if(we_smuoi()) require dirname(__FILE__).'/smuoi.php';

